package com.zh.note.huawei.twohundred.跳格子2;

/**
 * https://dream.blog.csdn.net/article/details/130996767
 */
public class Main {

    public static void main(String[] args) {
        //
        // Scanner scanner = new Scanner(System.in);
        //
        // String s = scanner.nextLine();
        String s = "1 3 1 1 1";
        String[] strings = s.split(" ");
        int[] nums = new int[strings.length - 1];
        for (int i = 0; i < nums.length; i++) {
            nums[i] = Integer.parseInt(strings[i]);
        }

        int res = maxSumNonAdjacent(nums);

        System.out.println(res);
    }

    public static int maxSumNonAdjacent(int[] nums) {
        int n = nums.length;
        if (n == 0) {
            return 0;
        } else if (n == 1) {
            return nums[0];
        } else if (n == 2) {
            return Math.max(nums[0], nums[1]);
        }

        int prevMax = nums[0];
        int currMax = Math.max(nums[0], nums[1]);

        for (int i = 2; i < n; i++) {
            int temp = currMax;// 当前最大值
            currMax = Math.max(currMax, prevMax + nums[i]); // 更新当前最大值
            prevMax = temp;
        }

        return currMax;
    }
}

